package com.xu.handler;

import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;
import com.xu.util.Tools;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.logging.Handler;

public class MyInvocationHandler implements InvocationHandler {
    //代理对象
    private Object target=null;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object res=null;
        String methodName = method.getName();
//        System.out.println(methodName);
        System.out.println("执行代理类MyInvocationHandler的invoke方法");
        //执行目标方法之前
        Tools.doLog();    //这里做功能增强
        //执行target对象的方法
        res=method.invoke(target,args);  //doSome

        if("doSome".equals(methodName) ){
            //执行目标方法之后
            Tools.doTranc();
        }


        return res;
    }
}
